﻿using drewCo.Curations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CurationsTester
{
  // ============================================================================================================================
  [TestClass]
  public class ICollectionTesters
  {


    // --------------------------------------------------------------------------------------------------------------------------
  /// <summary>
  /// Shows that we can partition lists in different ways.
  /// This case was written to solve some issues with leftover items..
  /// </summary>
    [TestMethod]
    public void CanPartitionList()
    {

      const int CHUNK_SIZE = 5;
      List<int> one = new List<int>() { 1 };

      var partedOne = ICollectionHelper.PartitionList(one, CHUNK_SIZE);
      Assert.AreEqual(1, partedOne.Count, "There should be one partition in the list! [1]");
      Assert.AreEqual(1, partedOne[0].Count, "There should be one item in the partition! [1]");

      List<int> two = new List<int>() { 1,2,3,4,5,6,7,8,9,10 };
      var partedTwo = ICollectionHelper.PartitionList(two, CHUNK_SIZE);
      Assert.AreEqual(2, partedTwo.Count, "There should be two partitions in the list! [2]");
      foreach (var subList in partedTwo)
      {
        Assert.AreEqual(CHUNK_SIZE, subList.Count, "The sublist should contain {0} items!", CHUNK_SIZE);
      }

      List<int> three = new List<int>() { 1,2,3,4,5,6,7 };
      var partedThree = ICollectionHelper.PartitionList(three, CHUNK_SIZE);
      Assert.AreEqual(2, partedThree.Count, "There should be two partitions in the list! [3]");
      Assert.AreEqual(5, partedThree[0].Count, "There should be {0} items in the partition! [3]", CHUNK_SIZE);
      Assert.AreEqual(2, partedThree[1].Count, "There should be {0} items in the partition! [3]", three.Count - CHUNK_SIZE);

    }


    //// --------------------------------------------------------------------------------------------------------------------------
    ///// <summary>
    ///// Shows that we can copy an ICollection(T) to a List(T)
    ///// </summary>
    //[TestMethod]
    //public void CanCopyList()
    //{
    //  int[] myNumbers = {1,2,3,4,5};

    //  List<int> copy=  ICollectionHelper.Copy(myNumbers);

    //  for (int i = 0; i < myNumbers.Length; i++)
    //  {
    //    Assert.AreEqual(myNumbers[i], copy[i], "Bad values at index #{0}!",i);
    //  }
    //}


    // --------------------------------------------------------------------------------------------------------------------------
    [TestMethod]
    public void CanAddUniqueItems()
    {
      List<int> evenList = new List<int>() { 2, 4, 6, 8 };
      int expectedCount = evenList.Count;

      // Add something that is already in the list.
      ICollectionHelper.AddUnique(evenList, 2);
      Assert.AreEqual(expectedCount, evenList.Count);

      // Now add something that isn't in the list.
      ICollectionHelper.AddUnique(evenList, 10);
      Assert.AreEqual(expectedCount + 1, evenList.Count);

    }



  }
}
